package data.demo1;

public class DynamicArray {
    //数组的插入、删除
    private int size = 0;
    private int capacity = 8;
    private int[] array = new int[capacity];
        public void addLast(int element){
            add(size,element);
        }

//插入
    public void add(int index, int element) {
        if (index >= 0 && index < size) {
            System.arraycopy(array, index, array, index + 1, size - index);

        }array[index] = element;
        size++;
    }
    public int get(int index){   //index = 0~size-1
            return array[index];
    }
}
